#!/bin/bash
fileName=$1
echo $fileName
oldPid=$(ps -ef | grep $fileName | grep -v 'grep' |awk '{ print $2}')
if [ -n "$oldPid" ]; then
    echo "close old worker process, id is $oldPid"
    # kill -9 $oldPid
    # echo "kill old worker process success"
fi
echo "start new worker process"
nohup python3 -u $fileName start > agent.log 2>&1 &
sleep 2
newPid=$(ps -ef | grep $fileName | grep -v 'grep' |awk '{ print $2}')
## 如果newPid 不存在， 说明启动失败
if [ ! -n "$newPid" ]; then
    echo "start worker process failed"
    exit 1
fi
echo "deploy success, new worker process id is $newPid"